import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:twitter_app/common/components/app_button.dart';
import 'package:twitter_app/common/components/app_text_field.dart';

import 'index.dart';

class RegisterPage extends GetView<RegisterController> {
  final void Function() onTap;
  const RegisterPage({super.key, required this.onTap});

  // 主视图
  Widget _buildView(BuildContext context) {
    final TextEditingController usernamecontroller = TextEditingController();
    final TextEditingController emailcontroller = TextEditingController();
    final TextEditingController passwordcontroller = TextEditingController();
    final TextEditingController confirmPasswordcontroller =
        TextEditingController();
    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const SizedBox(
                height: 50,
              ),
              Icon(
                Icons.lock_open_rounded,
                size: 72,
                color: Theme.of(context).colorScheme.primary,
              ),
              const SizedBox(
                height: 50,
              ),
              // 欢迎回来
              Text(
                "欢迎回来",
                style: TextStyle(
                  color: Theme.of(context).colorScheme.primary,
                  fontSize: 16,
                ),
              ),
              const SizedBox(
                height: 20,
              ),
              // 账号
              AppTextField(
                  controller: usernamecontroller,
                  hintText: '请输入用户名',
                  obscureText: false),
              const SizedBox(
                height: 20,
              ),
              // 账号
              AppTextField(
                  controller: emailcontroller,
                  hintText: '请输入邮箱',
                  obscureText: false),
              const SizedBox(
                height: 20,
              ),
              AppTextField(
                  controller: confirmPasswordcontroller,
                  hintText: '请输入确认密码',
                  obscureText: true),
              // 忘记密码
              const SizedBox(
                height: 20,
              ),
              AppTextField(
                  controller: passwordcontroller,
                  hintText: '请输入密码',
                  obscureText: true),
              // 忘记密码
              const SizedBox(
                height: 20,
              ),

              const SizedBox(
                height: 10,
              ),
              // 登录按钮
              AppButton(
                text: '注册',
                onTap: () {},
              ),
              const SizedBox(
                height: 50,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    '已经是会员?',
                    style: TextStyle(
                      color: Theme.of(context).colorScheme.primary,
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  GestureDetector(
                    onTap: onTap,
                    child: Text(
                      '点击登录',
                      style: TextStyle(
                        color: Theme.of(context).colorScheme.primary,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<RegisterController>(
      init: RegisterController(),
      id: "register",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("register")),
          body: SafeArea(
            child: _buildView(context),
          ),
        );
      },
    );
  }
}
